package com.delu.controller;

import com.delu.data.Result;
import com.delu.dto.CouponDTO;
import com.delu.em.ResultEnum;
import com.delu.entity.Coupon;
import com.delu.mapper.CouponsMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("coupon")
@Api("优惠卷管理")
public class CouponController {
    @Resource
    private CouponsMapper couponsMapper;

    @PostMapping("selectAll")
    @ApiOperation(value = "查询所有优惠券")
    public Result selectCouponList(){
        try {
            List<Coupon> coupons = couponsMapper.selectList(null);
            return Result.response(ResultEnum.SUCCESS).setData(coupons);
        }catch (Exception e){
            e.printStackTrace();
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }

    @GetMapping
    @ApiOperation("优惠卷查询")
    @ApiImplicitParam(name = "couponId",value = "优惠券ID",required = true,paramType = "query")
    public Result selectCoupon(@RequestParam("couponId")Integer couponId){
        System.out.println("优惠卷信息" + couponId);
        List<Coupon> couponList = couponsMapper.selectCoupon(couponId);
        return Result.response(ResultEnum.SUCCESS).setData(couponList);
//        Result<CouponDTO> couponDTOResult = couponServiceFeign.selectCoupon(couponId);
//        return Result.response(ResultEnum.SUCCESS).setData(couponDTOResult);
    }
}
